<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="订单号" prop="order">
                <el-input v-model="form.order" clearable></el-input>
        	</el-form-item>
            <el-form-item label="钱" prop="money">
                <el-input-number v-model="form.money"></el-input-number>
        	</el-form-item>
            <el-form-item label="订单ids" prop="order_ids">
                <el-input v-model="form.order_ids" clearable></el-input>
        	</el-form-item>
            <el-form-item label="支付状态" prop="pay_status">
                <el-radio v-model="form.pay_status" v-for="(item,index) in pay_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="用户id" prop="user_id">
                <el-input-number v-model="form.user_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="创建时间" prop="time">
                <el-date-picker v-model="form.time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="支付方式" prop="pay_type">
                <el-radio v-model="form.pay_type" v-for="(item,index) in pay_type_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="支付时间" prop="pay_time">
                <el-date-picker v-model="form.pay_time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="实际支付（分）" prop="pay_money">
                <el-input-number v-model="form.pay_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="支付者openid" prop="pay_openid">
                <el-input v-model="form.pay_openid" clearable></el-input>
        	</el-form-item>
            <el-form-item label="实际支付金额" prop="pay_fee">
                <el-input-number v-model="form.pay_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="支付贝壳总数" prop="shell_fee">
                <el-input-number v-model="form.shell_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="积分支付数" prop="score_fee">
                <el-input-number v-model="form.score_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="积分服务费金额" prop="score_money_fee">
                <el-input-number v-model="form.score_money_fee"></el-input-number>
        	</el-form-item>
            <el-form-item label="更新支付时间" prop="pay_update_time">
                <el-date-picker v-model="form.pay_update_time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="抵扣金额" prop="gift_money">
                <el-input-number v-model="form.gift_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="余额支付金额" prop="balance_money">
                <el-input-number v-model="form.balance_money"></el-input-number>
        	</el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					order: '',
					money: '',
					order_ids: '',
					pay_status: '',
					user_id: '',
					time: '',
					pay_type: '',
					pay_time: '',
					pay_money: '',
					pay_openid: '',
					pay_fee: '',
					shell_fee: '',
					score_fee: '',
					score_money_fee: '',
					pay_update_time: '',
					gift_money: '',
					balance_money: '',
                },
                rules: {
                },
				pay_status_option:{"1":"待支付","2":"已支付","3":"已退款","4":"已超时"},
				pay_type_option:{"wechat":"微信支付","alipay":"支付宝","wallet":"钱包支付","score":"积分支付","shell":"贝壳支付","mix":"混合支付"},
            }
        },
        methods: {
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.order_total[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>